<template>
  <header :class="['header', shadow && 'shadow']" id="header" :style="styleComputed">
    <main>
      <a href="/" class="logo">
        <img :src="logo" />
        <span>KEENOHO</span>
      </a>
      <nav>
        <a href="#sec-2" @click.stop.prevent="scrollToDom('#sec-2')">
          <span>关于我们</span>
        </a>
        <a href="#sec-5" @click.stop.prevent="scrollToDom('#sec-5')">
          <span>开发案例</span>
        </a>
        <a href="#sec-7" class="no-line" @click.stop.prevent="scrollToDom('#sec-7')">
          <button class="co-btn arrow">联系我们</button>
        </a>
      </nav>
    </main>
  </header>
</template>
<script>
import { scrollToDom } from '../util';

export default {
  name: 'co-header',
  props: {
    shadow: {
      type: Boolean,
      default: false,
    },
    maxPercent: {
      type: Number,
      default: 0,
    },
  },
  computed: {
    logo() {
      return this.$config?.CONFIG_APP_LOGO_WHITE;
    },
    styleComputed() {
      return {
        backgroundColor: `rgba(0, 0, 0, ${this.maxPercent})`,
      };
    },
  },
  methods: {
    scrollToDom,
  },
};
</script>
<style lang="less" scoped>
.header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 99;
  will-change: background-color;

  &.shadow {
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
  }

  main {
    max-width: 1280px;
    margin: 0 auto;
    box-sizing: border-box;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .logo {
    display: flex;
    align-items: center;
    color: #fff;
    flex-shrink: 0;
    img {
      height: 50px;
      width: auto;
    }
    span {
      margin-left: 16px;
      font-family: 'Outfit-Bold';
      font-size: 36px;
    }
  }

  nav {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-grow: 1;
    a {
      position: relative;
      color: #fff;
      font-weight: bold;
      font-size: 20px;
      cursor: pointer;

      & + a {
        margin-left: 48px;
      }

      &::after {
        content: '';
        position: absolute;
        bottom: -4px;
        left: 0;
        width: 0;
        height: 2px;
        background-color: #fff;
        transition: width 0.2s linear;
      }

      &:hover {
        &::after {
          width: 100%;
        }
      }

      &.no-line {
        &::after {
          display: none;
        }
      }
    }
  }
}

@media screen and (max-width: 1000px) {
  .header {
    .logo {
      img {
        height: 38px;
      }
      span {
        margin-left: 12px;
        font-size: 27px;
      }
    }
    nav {
      a:not(.no-line) {
        display: none;
      }

      a.no-line {
        margin-left: 0;
      }
    }
  }
}
</style>
